package com.lz.football.module.playerCenter.ComboBox
{
	import com.lz.football.module.base.IComponent;
	
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.text.TextField;

	/**
	 * 下拉列表 
	 * @author Administrator
	 * 
	 */	
	public class ComboBox extends Sprite implements IComponent
	{
		/**
		 * 皮肤 
		 */
		private var symbolSkin:MovieClip;
		/**
		 * 
		 */
		private var _name:TextField;
//		/**
//		 * 
//		 */
//		private var formation:MovieClip;
		
		private var _comboBoxMenu:ComboBoxMunu;
		private var _data:Object;
		public function ComboBox()
		{
			super();
		}
		
		public function initUI(view:Object=null):void
		{
			symbolSkin = view as MovieClip;
//			formation = symbolSkin.formation
//			formation.gotoAndStop(1);
			
			_name = symbolSkin.battleText;
			addEvtListener();
			_comboBoxMenu = new ComboBoxMunu();
			_comboBoxMenu.callBack = selectItem;
			_comboBoxMenu.y = symbolSkin.height/*+symbolSkin.y*/ - 2;
//			_comboBoxMenu.x = symbolSkin.x;
			
		}
		public function setData($arr:Array,$value:int):void
		{
			_comboBoxMenu.setData($arr,$value);
		}
		public function addEvtListener():void
		{
			symbolSkin.addEventListener(MouseEvent.CLICK,onClickHandler);
		}
		
		/**
		 * 
		 * @param event
		 * 
		 */
		private function onClickHandler(event:MouseEvent):void
		{
			symbolSkin.addChild(_comboBoxMenu);
			_comboBoxMenu.addEvent();
		}
		public function removeEvtListener():void
		{
			symbolSkin.removeEventListener(MouseEvent.CLICK,onClickHandler);
		}
		
		public function destroyView():void
		{
			_comboBoxMenu.destroyView();
			removeEvtListener();
			_data = null;
			_comboBoxMenu = null;
			symbolSkin = null;
		}
		/**
		 *选中了列表 
		 * @param $obj
		 * 
		 */
		private function selectItem($obj:Object):void
		{
			_data = $obj;
//			formation.gotoAndStop($obj.value);
			_name.text = $obj.label +"";
			this.dispatchEvent(new Event(Event.SELECT));
		}

		/**
		 *默认显示 
		 * 
		 */
		public function defaultSelect($obj:Object):void
		{
			_data = $obj;
//			formation.gotoAndStop($obj.value);
			_name.text = $obj.label;
		}
		/**
		 *选中数据 
		 */
		public function get data():Object
		{
			return _data;
		}

	}
}